package day01;

import java.util.ArrayList;

public class Demo04 {
    public static void main(String[] args) {
        //ArrayList 不能进行并发读写
        ArrayList<String> list1 = new ArrayList<>();
        list1.add("Tom");
        list1.add("Jerry");
        list1.add("Andy");
        list1.add("Mac");
        Thread t1 = new Thread(){
            @Override
            public void run() {
                for (String name:list1){
                    System.out.println(name);
                    try {
                        sleep(10);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        };
        Thread t2 = new Thread(){
            @Override
            public void run() {
                list1.add(0, "John");
                try {
                    sleep(10);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        };
        t1.start();
        t2.start();

    }
}
